1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
/*
Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org>
This file is part of JBriscola.
JBriscola is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
JBriscola is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with JBriscola; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Frame extends JFrame {
public static boolean mazzo;
public static Main main;
public static Pannello pannello;
public static JButton button;
public static ImageIcon retro1, retro2, ultimaCarta;
public static ImageIcon[] giocata = new ImageIcon[2];
public static ImageIcon[] carteInMano = new ImageIcon[3];
public static ImageIcon[] carteCPU = new ImageIcon[3];
public static ImageIcon[] arrayCarteMescolate = new ImageIcon[40];
public static ImageIcon[][] arrayCarte = new ImageIcon[10][4];
public Frame() {
super( "Tronto's JBriscola 0.1" );
mazzo = true;
main = new Main();
pannello = new Pannello();
button = new JButton( "Prendi/Lascia carte" );
button.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent e ) {
if ( giocata[0] != null && giocata[1] != null )
main.mano++;
else
JOptionPane.showMessageDialog( Frame.this, "Prima gioca!" );
try {
main.chiPrende();
} catch ( Exception ex ) {
JOptionPane.showMessageDialog( Frame.this, "Prima gioca!" );
}
if ( main.mano == 16 )
JOptionPane.showMessageDialog( Frame.this, "Ultime 4 mani - occhio alla briscola!" );
if ( main.mano == 17 ) {
mazzo = false;
ultimaCarta = null;
pannello.repaint();
Frame.this.repaint();
}
if ( main.mano == 20 )
JOptionPane.showMessageDialog( Frame.this, "Giocatore: " + main.punteggio + "\nComputer: " + main.punteggioCPU + "\n\nMa grazie tante, il computer gioca a caso!\nNon serve che ti gasi tanto." );
}
} );
retro1 = new ImageIcon( ClassLoader.getSystemResource( "img/retro1.jpg" ) );
retro2 = new ImageIcon( ClassLoader.getSystemResource( "img/retro2.jpg" ) );
for (int i = 0; i < 10; i++)
for (int j = 0; j < 4; j++)
arrayCarte[i][j] = new ImageIcon( ClassLoader.getSystemResource( "img/" + (i+1) + "-" + (j+1) + ".jpg" ) );
main.mischia();
carteInMano[0] = arrayCarteMescolate[0];
carteInMano[1] = arrayCarteMescolate[1];
carteInMano[2] = arrayCarteMescolate[2];
carteCPU[0] = arrayCarteMescolate[3];
carteCPU[1] = arrayCarteMescolate[4];
carteCPU[2] = arrayCarteMescolate[5];
ultimaCarta = arrayCarteMescolate[39];
setLayout( new BorderLayout() );
add( pannello, BorderLayout.CENTER );
add( button, BorderLayout.SOUTH );
addMouseListener(
new MouseAdapter() {
public void mouseClicked ( MouseEvent e ) {
if ( mettiCarta( e.getX(), e.getY() ) ) {
if ( !main.CPUHaGiocato )
main.giocaCPU();
}
}
}
);
}
public boolean mettiCarta( int x, int y ) {
if ( !main.toccaAllaCPU && giocata[0] == null ) {
if ( x > 230 && x < 290 && y > 340 && y < 566 ) {
giocata[0] = carteInMano[0];
carteInMano[0] = null;
pannello.repaint();
return true;
}
if ( x > 300 && x < 360 && y > 340 && y < 566 ) {
giocata[0] = carteInMano[1];
carteInMano[1] = null;
pannello.repaint();
return true;
}
if ( x > 370 && x < 430 && y > 340 && y < 566 ) {
giocata[0] = carteInMano[2];
carteInMano[2] = null;
pannello.repaint();
return true;
}
}
return false;
}
}
|